package com.chenglai.video.controller;

import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.chenglai.video.pojo.VideoCategory;
import com.chenglai.video.pojo.VideoInfo;
import com.chenglai.video.service.VideoCategoryService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 类描述：视频分类
 *
 * @Author rxh
 * @Date 2023/11/16 8:33
 */
@RestController
@RequestMapping("/videoCategory/")
public class VideoCategoryController {

    @Resource
    private VideoCategoryService videoCategoryService;

    /**
     * 获取视频列表
     *
     * @param page   页码
     * @param size   数量
     * @param shopId 门店ID
     * @return
     */
    @PostMapping("getVideoCateGoryList")
    @ApiOperation(value = "获取视频列表")
    public Result getVideoCateGoryList(Integer page, Integer size, Integer shopId) {
        try {
            PageInfo pageInfo = videoCategoryService.getVideoCateGoryList(page, size, shopId);
            return new Result(true, StatusCode.OK, "操作成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 添加/修改视频分类
     *
     * @param videoCategory 视频分类实体类
     */
    @PostMapping("editVideoCategory")
    @ApiOperation(value = "添加/修改视频分类")
    public Result editVideoCategory(VideoCategory videoCategory) {
        try {
            videoCategoryService.editVideoCategory(videoCategory);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 删除视频分类
     *
     * @param categoryId 视频分类ID
     */
    @PostMapping("delVideoCategory")
    @ApiOperation(value = "删除视频分类")
    public Result delVideoCategory(Integer categoryId) {
        try {
            Map<String, Object> data = videoCategoryService.delVideoCategory(categoryId);
            return new Result(true, StatusCode.OK, "操作成功", data);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 视频分类详情
     *
     * @param categoryId 视频分类ID
     */
    @PostMapping("detail")
    @ApiOperation(value = "视频分类详情")
    public Result categoryDetail(Integer categoryId) {
        try {
            VideoCategory detail = videoCategoryService.categoryDetail(categoryId);
            return new Result(true, StatusCode.OK, "查询成功", detail);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

    /**
     * 根据视频分类查询视频集合
     *
     * @param categoryId 视频分类ID
     */
    @PostMapping("videoList")
    @ApiOperation(value = "根据视频分类查询视频集合")
    public Result queryVideoListByCategoryId(Integer categoryId) {
        try {
            List<VideoInfo> list = videoCategoryService.queryVideoListByCategoryId(categoryId);
            return new Result(true, StatusCode.OK, "查询成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

}
